<template>
  <div class="app-container">
    <!--工具栏-->
    <div v-if="!showComponents" class="head-container">
      <div v-if="crud.props.searchToggle" class="search-tools">
        <!-- 搜索 -->
        <el-button class="tools-all" size="small" type="primary" round>全部</el-button>
        <div class="tools-right">
          <template v-for="item in searchTools">
            <div v-if="item.menuType==='button' && item.pageUrl ==='group'" :key="item.id" class="tools-group">
              <span>{{ item.name }}</span>
              <div class="group-btns">
                <el-badge v-for="sub in item.children" :key="sub.id" :value="12" class="btn">
                  <el-button size="small" round @click="() =>{searchButton(sub)}">{{ sub.name }}</el-button>
                </el-badge>
                <!-- <el-button v-for="sub in item.children" :key="sub.id" round>{{ sub.name }}</el-button> -->
              </div>
            </div>
          </template>
        </div>
        <!-- <rrOperation :crud="crud"></rrOperation> -->
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation>
        <div slot="right">
          <el-input placeholder="请输入内容" style="width:150px;display:inline-block;" suffix-icon="el-icon-search"></el-input>
          <!-- <el-input placeholder="请选择日期" style="width:150px;display:inline-block;" suffix-icon="el-icon-date"></el-input> -->
          <el-date-picker style="width:150px;display:inline-block;" type="date" placeholder="选择日期" suffix-icon="el-icon-date"></el-date-picker>

          <rrOperation :crud="crud"></rrOperation>
        </div>
      </crudOperation>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="ID">
            <el-input v-model="form.id" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="form.patientName" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-radio v-for="item in dict.gender" :key="item.id" v-model="form.gender" :label="item.value">{{ item.label }}</el-radio>
          </el-form-item>
          <el-form-item label="出生日期">
            <el-date-picker v-model="form.birthDay" type="datetime" style="width: 370px;"></el-date-picker>
          </el-form-item>
          <el-form-item label="家长姓名">
            <el-input v-model="form.parent" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="家长联系方式">
            <el-input v-model="form.parentMobile" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker v-model="form.createDate" type="datetime" style="width: 370px;"></el-date-picker>
          </el-form-item>
          <el-form-item label="主管医生ID，参考 t_doctor">
            <el-input v-model="form.doctorId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="诊所ID">
            <el-input v-model="form.clinicId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="所属部门">
            <el-input v-model="form.deptId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="是否标星收藏，0未收藏，1已收藏">
            <el-input v-model="form.star" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="患者头像URL">
            <el-input v-model="form.photoUrl" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="产品规则">
            <el-input v-model="form.productRuleId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="套餐规则">
            <el-input v-model="form.packageRuleId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="是否已归档 0 未归档 1 已归档 已归档普通查询不可见">
            <el-input v-model="form.archived" style="width: 370px;"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" stripe :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="photoUrl" width="120" sortable label="患者头像">
          <template slot-scope="scope">
            <img :src="scope.row.photoUrl" class="user-avatar" />
          </template>
        </el-table-column>
        <!-- <el-table-column prop="id" sortable label="ID"></el-table-column> -->
        <el-table-column prop="patientName" width="150" sortable label="患者姓名"></el-table-column>
        <el-table-column prop="parentProfession" width="150" sortable label="诊疗阶段"></el-table-column>
        <el-table-column prop="parentProfession1" width="150" sortable label="套餐名称"></el-table-column>
        <el-table-column prop="parentProfession2" width="150" sortable label="治疗阶段"></el-table-column>
        <el-table-column prop="createDate" width="150" sortable label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="parentProfession3" width="150" sortable label="诊疗状态"></el-table-column>
        <el-table-column prop="parentProfession4" width="150" sortable label="描述"></el-table-column>
        <el-table-column prop="parentProfession5" width="150" sortable label="订单状态"></el-table-column>
        <!-- <el-table-column prop="gender" sortable label="性别">
          <template slot-scope="scope">
            {{ dict.label.gender[scope.row.gender] }}
          </template>
        </el-table-column>
        <el-table-column prop="birthDay" width="150" sortable label="出生日期">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.birthDay) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="compliance" width="180" sortable label="患者依从性预测">
          <template slot-scope="scope">
            {{ dict.label.patient_compliance[scope.row.compliance] }}
          </template>
        </el-table-column>
        <el-table-column prop="parent" sortable width="150" label="家长姓名"></el-table-column>
        <el-table-column prop="relationship" width="150" sortable label="家长关系">
          <template slot-scope="scope">
            {{ dict.label.patient_parent_rel[scope.row.relationship] }}
          </template>
        </el-table-column>
        <el-table-column prop="parentProfession" width="150" sortable label="家长职业"></el-table-column>
        <el-table-column prop="parentMobile" width="150" sortable label="家长联系方式"></el-table-column>
        <el-table-column prop="orthodonticHis" width="150" sortable label="家长正畸史"></el-table-column>
        <el-table-column prop="createDate" width="150" sortable label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="doctorId" width="150" sortable label="主管医生ID"></el-table-column>
        <el-table-column prop="clinicId" width="150" sortable label="诊所ID"></el-table-column>
        <el-table-column prop="deptId" width="150" sortable label="所属部门"></el-table-column>
        <el-table-column prop="tags" sortable label="标签"></el-table-column>
        <el-table-column prop="star" sortable label="收藏"></el-table-column>
        <el-table-column prop="productRuleId" width="150" sortable label="产品规则"></el-table-column>
        <el-table-column prop="packageRuleId" width="150" sortable label="套餐规则"></el-table-column>
        <el-table-column prop="archived" width="150" sortable label="是否已归档">
          <template slot-scope="scope">
            {{ dict.label.patient_archive[scope.row.archived] }}
          </template>
        </el-table-column> -->
        <el-table-column fixed="right" label="操作" width="100px" align="center">
          <!-- <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission"></udOperation>
          </template> -->
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination></pagination>
    </div>
    <div v-else class="create" style="margin: -20px -20px -45px">
      <Create v-if="showComponents === 'add'"></Create>
      <PatientDetails v-if="showComponents === 'visit'"></PatientDetails>
    </div>
  </div>

</template>

<script>
import crudPatient from '@/api/patient';
import CRUD, { presenter, header, form, crud } from '@crud/crud';
import rrOperation from '@crud/RR.operation';
import crudOperation from '@crud/CRUD.operation';
// import udOperation from '@crud/UD.operation';
import pagination from '@crud/Pagination';
// import DateRangePicker from '@/components/DateRangePicker';
import { mapGetters } from 'vuex';
// import utils from '@/utils';
import Create from './Create';
import PatientDetails from '@/views/components/patientDetails';

const defaultForm = { id: null, patientName: null, gender: null, birthDay: null, compliance: null, parent: null, relationship: null, parentProfession: null, parentMobile: null, orthodonticHis: null, createDate: null, doctorId: null, clinicId: null, deptId: null, tags: null, star: null, photoUrl: null, productRuleId: null, packageRuleId: null, archived: null };
export default {
  name: 'Patient',
  components: { pagination, crudOperation, rrOperation, Create, PatientDetails },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['gender', 'patient_compliance', 'patient_parent_rel', 'patient_archive'],
  cruds() {
    return CRUD({
      title: 'PatientService',
      url: '/patient/queryPage',
      sort: 'id,desc',
      crudMethod: { ...crudPatient },
      props: { searchToggle: false },
      optShow: { add: false, download: false }
    });
  },
  data() {
    return {
      //   permission: {
      //     // add: ['admin', 'patient:add'],
      //     // edit: ['admin', 'patient:edit'],
      //     // del: ['admin', 'patient:del']
      //   },
      rules: {
      },
      searchTools: [],
      queryTypeOptions: [
        { key: 'id', display_name: 'ID' },
        { key: 'patientName', display_name: '姓名' },
        { key: 'gender', display_name: '性别' },
        { key: 'parent', display_name: '家长姓名' },
        { key: 'parentMobile', display_name: '家长联系方式' },
        { key: 'doctorId', display_name: '主管医生ID，参考 t_doctor' },
        { key: 'clinicId', display_name: '诊所ID' },
        { key: 'deptId', display_name: '所属部门' }
      ],
      showComponents: ''
    };
  },
  computed: {
    ...mapGetters([
      'menusMap',
      'autoPath',
      'menusCode',
      'codes',
      'searchInfo'
    ])
  },
  watch: {
    searchInfo(newVal, oldVal) {
      console.warn(newVal.code, '||', oldVal.code);
      if (newVal.code === 'doc:work:add') {
        this.showComponents = 'add';
      } else if (newVal.code === 'doc:work:visit') {
        this.showComponents = 'visit';
      }
    }
  },
  mounted() {
    this.searchTools = this.menusCode[this.codes.DOC_WORK] && this.menusCode[this.codes.DOC_WORK].children;
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true;
    },
    searchButton(item) {
      console.warn(item.code, item.name);
    }
  }
};
</script>

<style lang="scss" scoped>
.app-container {
  .head-container {
    .search-tools {
      .tools-all {
        //   margin-top:10px;
        vertical-align: top;
      }
      .tools-right {
        display: inline-block;
        border-left: 1px solid #e6e6e6;
        padding-left: 10px;
        .tools-group {
          .group-btns {
            display: inline-block;
            margin-left: 30px;
            margin-bottom: 20px;
            .btn {
              margin-right: 30px;
            }
          }
        }
      }
    }
  }
}
</style>
